<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@page import="issuedfileaction.DBConnection;"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>       
    <title>查询经销商</title>    
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>  
  <body> 
  <%
      int PageSize; //一页显示的记录数
	  int TotalRow; //记录总数
	  int TotalPageCount; //总页数
	  int currentPage; //待显示页码
	  int BeginRow;
	  int EndRow;
	  String strPage;	  
	  //设置一页显示的记录数 
	  String CustomerCode="";
	  String CustomerName="";
	  String CurrentPage="";
	  try{
	      CustomerCode=request.getParameter("CustomerCode");
	  }catch(Exception e){
	      CustomerCode="";
	  }
	  try{
	      CustomerName=new String(request.getParameter("CustomerName").getBytes("ISO-8859-1"),"utf-8");
	  }catch(Exception e){
	      CustomerName="";
	  }
	  try{
	      CurrentPage=request.getParameter("CurrentPage");
	  }catch(Exception e){
	      CurrentPage="1";
	  }	  	    
	  DBConnection db=new DBConnection();
	  String StrSql=" select * from (select a.orgcode,a.orgname,rownum m from (select orgcode,orgname,rownum c from organization) a "
	               +" where 1=1 ";
	  String StrTotalSql=" select count(*) from organization where 1=1 ";
	  
      //记算总页数    	  
	  if(CustomerCode!=null){
	     StrSql=StrSql+" and orgcode like '%"+CustomerCode+"%' ";
	     StrTotalSql=StrTotalSql+" and orgcode like '%"+CustomerCode+"%' ";
	  }
	  
	  if(CustomerName!=null){
	    StrSql=StrSql+" and orgname like '%"+CustomerName+"%' ";
	    StrTotalSql=StrTotalSql+" and orgname like '%"+CustomerName+"%' ";
	  }	   
	  PageSize = 10;
	  //取得待显示页码
	  strPage = CurrentPage;
	  if(strPage==null){
	     //表明在QueryString中没有page这一个参数，此时显示第一页数据  
	     currentPage = 1;
	  } else{
	     //将字符串转换成整型  	  
	     currentPage = Integer.parseInt(strPage);
	     if(currentPage< 1) currentPage = 1;
	  }
	  TotalRow = db.GetTotalRow(StrTotalSql);
      TotalPageCount = (TotalRow+PageSize-1) / PageSize;  
      //调整待显示的页码  
      if(currentPage>TotalPageCount) 
         currentPage = TotalPageCount;
      BeginRow=(currentPage-1)*PageSize+1;
      EndRow=currentPage*PageSize;      
      StrSql=StrSql+" order by orgcode) ";
      StrSql=StrSql+" where m>="+BeginRow+" and m<="+EndRow+" ";
      Map<String,String> MapValue=new HashMap<String,String>();
      MapValue=db.GetMapValue(StrSql);
	  HttpSession httpSession = request.getSession();          
      httpSession.setAttribute("MapValue", MapValue);
      httpSession.setAttribute("currentPage",String.valueOf(currentPage));
      httpSession.setAttribute("TotalPageCount",String.valueOf(TotalPageCount));
      httpSession.setAttribute("CustomerCode",CustomerCode);
      httpSession.setAttribute("CustomerName",CustomerName);		      		    	  
	  response.sendRedirect("ViewCustomer.jsp");       
  %>
  </body>
</html>
